package com.czk.utils;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;

/**
 * @Author:ChenZhangKun
 * @Date: 2021/6/23 17:08
 */
@Aspect
//@Component
public class DataSourceAspect {
    @Around("@annotation(com.czk.utils.UseDataSource)")
    public Object routing(ProceedingJoinPoint signature, UseDataSource useDataSource) throws Throwable {
        String value = useDataSource.value();
        DataSourceContext.setDatasource(value);
        Object proceed = signature.proceed();
        DataSourceContext.remove();
        return proceed;
    }
}
